package com.shxzz.shortlink.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shxzz.shortlink.admin.common.convention.result.Result;
import com.shxzz.shortlink.admin.remote.LinkRemoteService;
import com.shxzz.shortlink.admin.remote.dto.req.LinkCreateReqDTO;
import com.shxzz.shortlink.admin.remote.dto.req.LinkPageReqDTO;
import com.shxzz.shortlink.admin.remote.dto.req.LinkUpdateReqDTO;
import com.shxzz.shortlink.admin.remote.dto.resp.LinkCreateRespDTO;
import com.shxzz.shortlink.admin.remote.dto.resp.LinkPageRespDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shxzz
 * @create 2023-12-19-11:14
 * @description 短链接控制层
 */
@RestController
public class LinkController {

    private final LinkRemoteService linkRemoteService = new LinkRemoteService(){};

    /**
     * 创建短链接
     * @param requireParam 创建短链接请求参数
     * @return 创建短链接信息
     */
    @PostMapping("/api/short-link/admin/v1/create")
    public Result<LinkCreateRespDTO> createLink(@RequestBody LinkCreateReqDTO requireParam) {
        return linkRemoteService.createLink(requireParam);
    }

    /**
     * 短链接分页查询
     * @param requireParam 分页查询参数
     * @return 分页查询结果
     */
    @GetMapping("/api/short-link/admin/v1/page")
    public Result<IPage<LinkPageRespDTO>> selectPageLink(LinkPageReqDTO requireParam) {
        return linkRemoteService.selectPageLink(requireParam);
    }

    /**
     * 短链接信息修改
     * @param requireParam 短链接修改请求参数
     */
    @PostMapping("/api/short-link/admin/v1/update")
    public Result<Void> updateLink(@RequestBody LinkUpdateReqDTO requireParam) {
        return linkRemoteService.updateLink(requireParam);
    }
}
